<?php
namespace app\walletyhbbadmin\controller;
use Think\Db;
use Think\request;
require_once (APP_PATH .'api/FinanceApi.php');
class Bank extends AdminBase {



    /**
     *企业邮箱
     */
    public function aboutme(){
      $res = DB::name('function')->order('time desc')->select();
      $this->assign('res',$res);
      return $this->fetch('bank/shoukuan');
    }
    public function addAbout()
    {
        return $this->fetch('bank/aboutme');
    }
    public function doaddAbout()
    {
       $data['title'] = input('name');
       $arr['content'] = input('phone');
       $data['content'] = md5($data['content']);
       $arr['chuanzhen'] = input('chuanzhen');
       $data['time'] = time();
      if(empty($data['title']))
      {
          $this->error('请补全信息');
      }
      if(empty($arr['content']))
      {
          $this->error('请补全信息');
      }
       if($arr['content'] != $arr['chuanzhen'])
       {
           $this->error('两次密码不一致');
       }
       $list = DB::name('function')->insert($data);
       if($list)
       {
           $this->success('添加成功','bank/aboutme');
       }
    }
    public function updateAbout()
    {
        $id = input('id');
        $list = DB::name('function')->where('id',$id)->find();
        $this->assign('list',$list);
	    return $this->fetch('bank/xiushoukuan');
    }
    public function dodateAbout()
    {
        $id = input('id');
        $list = DB::name('function')->where('id',$id)->find();
        $data['title'] = input('name');
        $arr['content'] = input('phone');
        $data['content'] = md5(input('phone'));
        if(empty($arr['content']))
        {
            $data['content'] = $list['content'];
        }
        $res = DB::name('function')->where('id',$id)->update($data);
        if($res)
        {
            $this->success('修改成功','bank/aboutme');
        }else{
            $this->error('未修改内容');
        }
    }
    public function delAbout()
    {
        $id = input('id');
        $list = DB::name('function')->where('id',$id)->delete();
        if($list)
        {
            $this->success('删除成功','bank/aboutme');
        }
    }

    /**
     * HCM
     */
    public function zhinan(){
        $list = DB::name('app_banks')->select();
        $this->assign('list',$list);
        return $this->fetch('bank/zhinan');
    }

    public function addZhinan(){
        return $this->fetch('bank/addZhinan');
    }
    public function doaddZhinan()
    {
        $data['b_name'] = input('name');
        $arr['password'] = input('phone');
        $data['password'] = md5(input('phone'));
        $arr['chuanzhen'] = md5(input('chuanzhen'));
        $data['time'] = time();
        if($data['b_name'] == null)
        {
            $this->error('请完善信息');
        }
        if($data['password'] == null)
        {
            $this->error('请完善信息');
        }
        if($arr['chuanzhen'] == null)
        {
            $this->error('请完善信息');
        }
        if($arr['password'] != $arr['chuanzhen'])
        {
            $this->error('两次密码不一致');
        }

        $res = DB::name('app_banks')->insert($data);
        if($res)
        {
            $this->success('添加成功','bank/question');
        }
    }

        public function delZhinan()
        {
            $id = input('id');
            $res = DB::name('app_banks')->where('id', $id)->delete();
            if ($res) {
                $this->success('删除成功', 'bank/zhinan');
            }
        }

        public function updateZhinan()
        {
            $id = input('id');
            $list = DB::name('App_bank')->where('id',$id)->find();
            $res = DB::name('App_bank_config')->where('id',$list['b_id'])->find();
            $arr = DB::name('App_bank_config')->select();
            $this->assign('list',$list);
            $this->assign('arr',$arr);
            $this->assign('res',$res);
            return $this->fetch();
         }
        public function doupdateZhinan()
        {
            $id = input('id');
            $list = DB::name('App_bank')->where('id',$id)->find();
            $data['b_name'] = input('name');
            $data['password'] = md5(input('phone'));
            if($data['b_name'] == null)
            {
                $this->error('请完善信息');
            }
            if($data['password'] == null)
            {
                $data['password'] = $list['password'];
            }
            $list = DB::name('App_banks')->where('id',$id)->update($data);
            if($list)
            {
                $this->success('修改成功','bank/zhinan');
            }else{
                $this->error('未修改信息','bank/zhinan');
        }
    }



    /**
     * 内部OA
     */
    public function question()
    {
        $list = DB::name('app_bank')->select();
        $this->assign('list',$list);
        return $this->fetch('bank/index');
    }
    public function addQuestion()
    {
        return $this->fetch('bank/question');
    }
    public function doaddQuestion()
    {
        $data['b_name'] = input('name');
        $arr['password'] = input('phone');
        $data['password'] = md5(input('phone'));
        $arr['chuanzhen'] = md5(input('chuanzhen'));
        $data['time'] = time();
        if($data['b_name'] == null)
        {
            $this->error('请完善信息');
        }
        if($data['password'] == null)
        {
            $this->error('请完善信息');
        }
        if($arr['chuanzhen'] == null)
        {
            $this->error('请完善信息');
        }
        if($arr['password'] != $arr['chuanzhen'])
        {
            $this->error('两次密码不一致');
        }

        $res = DB::name('app_bank')->insert($data);
        if($res)
        {
            $this->success('添加成功','bank/question');
        }
    }

    public function updateQuestion(){
        $data['value']=input('content');
        DB::name('config')->where('name','question')->update($data);
        $this->success('修改成功');
    }
    public function del()
    {
        $id = input('id');
        $res = DB::name('app_bank')->where('id',$id)->delete();
        if($res)
        {
            $this->success('删除成功','bank/question');
        }
    }

    public function updateBank()
    {
        $id = input('id');
        $list = DB::name('App_bank')->where('id',$id)->find();
        $res = DB::name('App_bank_config')->where('id',$list['b_id'])->find();
        $arr = DB::name('App_bank_config')->select();
        $this->assign('list',$list);
        $this->assign('arr',$arr);
        $this->assign('res',$res);
        return $this->fetch();
    }
    public function doupdateQuestion()
    {
        $id = input('id');
        $list = DB::name('App_bank')->where('id',$id)->find();
        $data['b_name'] = input('name');
        $data['password'] = md5(input('phone'));
        if($data['b_name'] == null)
        {
            $this->error('请完善信息');
        }
        if($data['password'] == null)
        {
            $data['password'] = $list['password'];
        }
        $list = DB::name('App_bank')->where('id',$id)->update($data);
        if($list)
        {
            $this->success('修改成功','bank/question');
        }else{
            $this->error('未修改信息','bank/question');
        }
    }

}